home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / njramd14.zip / NJRAMD.ASM < prev    next >
Assembly Source File  |  1991-06-23  |  42KB  |  1,436 lines

  1.  
  2. ;  Nifty James' Famous Expanded Memory Disk Drive
  3. ;  (C) Copyright 1987 by Mike Blaszczak.  All Rights Reserved
  4.  
  5. ;  Version 1.01  of  24 May 1987
  6. ;  Version 1.10  of  25 May 1987
  7. ;  Version 1.15  of  31 May 1987
  8. ;  Version 1.20  of  16 Oct 1987
  9. ;  Version 1.30  of  05 Dec 1989
  10. ;  Version 1.40  of  23 Jun 1991 
  11.  
  12. ;  Shareware  $15     Please register!
  13.  
  14. ;  Assemble with
  15. ;    MASM NJRAMD;
  16. ;        (Use MASM /DV286 NJRAMD; to assemble 286 version.)
  17. ;    LINK NJRAMD;
  18. ;    EXE2BIN NJRAMD.EXE NJRAMD.SYS
  19. ;    DEL NJRAMD.EXE
  20.  
  21. ;  --> DEVICE DRIVER FORMAT FILE <--
  22. ;  -->  REMEMBER TO USE EXE2BIN  <--
  23.  
  24. ; ---------------------------------------------------------------------------
  25.  
  26. ;   ASCII Characters
  27.  
  28. bell        equ    7        ; bell character
  29. tab        equ    9        ; tab character
  30. lf        equ    10        ; linefeed
  31. cr        equ    13        ; carriage return
  32. space        equ    32        ; space
  33. eos        equ    '$'        ; end of DOS string
  34.  
  35. ; ---------------------------------------------------------------------------
  36.  
  37. EMM        equ    067h        ; the E/EMS memory manager
  38.  
  39. ; ---------------------------------------------------------------------------
  40. ;   I/O Ports
  41.  
  42. Speak        equ    061h        ; speaker port
  43. SpeakMask    equ    011111110b    ; mask for speaker set bit
  44. SpeakToggle    equ    000000010b    ; toggle bit for the speaker
  45.  
  46. ; ---------------------------------------------------------------------------
  47. ;   DOS Calls
  48.  
  49. ; These are DOS functions used by the driver.
  50.  
  51. DisplayOut    equ    002h        ; call to print a single character
  52. PrintString    equ    009h        ; call to print a '$' string
  53. GetDOSVersion    equ    030h        ; call to get the DOS version #
  54.  
  55. ; ---------------------------------------------------------------------------
  56. ;  E/EMM Routines
  57.  
  58. ; These are the E/EMM functions that we use.  (These are specific functions
  59. ; of the EMM interrupt.)
  60.  
  61. E_PageBase    equ    041h        ; determine the Page Fram Base Addr
  62. E_Counts    equ    042h        ; determine free/total mem
  63. E_Open        equ    043h        ; open, allocate, obtain handle ID
  64. E_MapPage    equ    044h        ; map a logical page into window
  65. E_Version    equ    046h        ; get the E/EMM version number
  66. E_Save        equ    047h        ; save mapping context
  67. E_Restore    equ    048h        ; restore mapping context
  68.  
  69. ; ---------------------------------------------------------------------------
  70. ;  Driver Equates
  71.  
  72. ; This is the media descriptor byte.  Since our RAM drive is not 2 sided,
  73. ; does not have 8 sectors per track, and is not removable, we use 0F8h.
  74. ; At least, that's what the IBM DTR manual says.
  75.  
  76. MediaD        equ    0F8h
  77.  
  78. ; These are equates used by the driver.  They are all status and
  79. ; error flags, as defined in the DOS Technical Reference Manual.
  80.  
  81. ;                        FEDCBA9876543210 <- BIT NUMBERS
  82. errorflag    equ    01000000000000000b    ; error bit flag
  83. busystat    equ    00000001000000000b    ; busy status bit flag
  84. donestat    equ    00000000100000000b    ; done status bit flag
  85.  
  86. err_writeprot    equ    0        ; write protect violation
  87. err_badunit    equ    1        ; unknown unit number
  88. err_notready    equ    2        ; device not ready
  89. err_unknown    equ    3        ; unknown command
  90. err_CRC        equ    4        ; error CRC command
  91. err_reqlen    equ    5        ; bad request length
  92. err_seek    equ    6        ; seek failure
  93. err_badmedia    equ    7        ; bad media
  94. err_badsector    equ    8        ; sector not found
  95. err_badwrite    equ    10        ; write fault
  96. err_badread    equ    11        ; read fault
  97. err_general    equ    12        ; general failure
  98.  
  99. ; ---------------------------------------------------------------------------
  100. ;  Structure Definitions
  101.  
  102. ;  The structures defined here are used to find information in the
  103. ;  various request header formats.  Of course, being structures, they
  104. ;  don't take up space... they are used to define offsets for the
  105. ;  addressing of the request header.
  106.  
  107. rq    equ    es:[bx]            ; base address used in routines
  108.  
  109. ;  -- Request Header (General Format)
  110.  
  111. rhead    struc
  112.     rlen    db    ?    ; length of the structure
  113.     unitn    db    ?    ; unit number
  114.     command    db    ?    ; command code
  115.     status    dw    ?    ; status code (returned by us)
  116.         db    8 dup(?); reserved bytes
  117. rhead    ends
  118.  
  119.  
  120. ;  -- Request Header (INIT Command)
  121.  
  122. inithead    struc
  123.         db    (type rhead) dup (?)
  124.     units    db    ?    ; number of units
  125.     ndadro    dw    ?    ; ending address offset
  126.     ndadrs    dw    ?    ; ending address segment
  127.     bpboff    dw    ?    ; BPB offset pointer
  128.     bpbseg    dw    ?    ; BPB segment pointer
  129.     taglet    db    ?    ; drive tag letter
  130. inithead    ends
  131.  
  132. ;  -- Request Header (Media Check)
  133.  
  134. mediahead    struc
  135.         db    (type rhead) dup (?)
  136.     media    db    ?    ; our meida descriptor byte
  137.     change    db    ?    ; changed media flag
  138. mediahead    ends
  139.  
  140. ;  -- Request Header (Build BPB)
  141.  
  142. bbpbhead    struc
  143.         db    (type rhead) dup (?)
  144.         db    ?    ; media descriptor byte
  145.     baoff    dw    ?    ; transferr buffer address offset
  146.     baseg    dw    ?    ; transferr buffer address segment
  147.         dw    ?    ; BIOS parameter block pointer
  148.         dw    ?    ; BIOS parameter block pointer
  149. bbpbhead    ends
  150.  
  151. ;  -- Request Header (Read and Write)
  152.  
  153. rwhead        struc
  154.         db    (type rhead) dup (?)
  155.         db    ?    ; media descriptor byte
  156.     tbaoff    dw    ?    ; transferr buffer address offset
  157.     tbaseg    dw    ?    ; transferr buffer address segment
  158.     count    dw    ?    ; sector count
  159.     strtsec    dw    ?    ; starting sector number
  160. rwhead        ends
  161.  
  162.  
  163. ; With these headers defined as they are, access to the request header
  164. ; and command info fields is greatly simplified.  By setting ES:BX to
  165. ; point to the request header, the information can be easily referenced
  166. ; by using constructs such as
  167.  
  168. ;        mov    rq.count,ax
  169. ;  or
  170. ;        mov    al,rq.command
  171.  
  172. ; Note that any part of the program can easily reference any particular
  173. ; command's structure, since the line
  174.  
  175. ;        db    (type rhead) dup (?)
  176.  
  177. ; makes all the command-specific structures "equivalent".
  178.  
  179. ; Check to see if this is the 286 version
  180.  
  181. ifdef  V286
  182.     .286
  183.     if1
  184.         %OUT    Enhanced processor version
  185.     endif
  186.     ifdef    PCL
  187.     if1
  188.         %OUT    for the PC's Limited 286/386
  189.     endif
  190.     endif
  191. else
  192.     if1
  193.         %OUT    Standard Version
  194.     endif
  195. endif
  196.  
  197.  
  198. ;  This macro is used during debugging.  It prints a single character
  199. ; via the BIOS screen interface, and leaves the registers unchanged.
  200.  
  201. ifdef    DEBUG
  202.  
  203.     if1
  204.         %OUT  DEBUG Version
  205.     endif
  206.     PrintChar    macro    Char
  207.         ifdef    PCL
  208.  
  209.             push    ax
  210.             mov    al,Char
  211.             out    095h,al        ; put it digit 3 of smartvu
  212.             pop    ax
  213.  
  214.         else
  215.     
  216.             push    ax        ; save the regs
  217.             push    bx
  218.             push    dx
  219.             mov    ah,15
  220.             int    010h        ; get the current page
  221.             mov    al,Char
  222.             mov    ah,14        ; print the character
  223.             int    010h
  224.  
  225.             xor    dx,dx
  226.             mov    ah,0        ; also to printer
  227.             mov    al,Char
  228.             int    017h
  229.  
  230.             pop    dx
  231.             pop    bx        ;restore the regs
  232.             pop    ax
  233.  
  234.             endif
  235.             endm
  236.  
  237. else
  238.     PrintChar    macro    Char        ; if not debugging, blow it off
  239.             endm
  240. endif
  241.  
  242. ; ---------------------------------------------------------------------------
  243. ;  Public declarations for SYMDEB
  244.  
  245. ; These are public declarations included to allow SYMDEB to know where
  246. ; various lables and addresses are.  They are only needed for debugging,
  247. ; and serve no other useful purpose.
  248.  
  249. PUBLIC NextPlace
  250. PUBLIC Attrib, JumpTable, TopCommand, RBPoint, RBPointOff, RBPointSeg, SaveSS
  251. PUBLIC SaveSP, SaveAX, EMMHandle, EMMBase, StackTop, STRATPROC, Strategy
  252. PUBLIC INTPROC, Interrupt, NoSaveM, FreakOut, IOCTLInput, ReadNoWait
  253. PUBLIC InputStatus, InputFlush, badcommand, BigLog, NoRestore, MC, MediaCheck
  254. PUBLIC BBPB, BuildBPB, BPBArray, OurBoot, OurBPB, SecSize, SecPerCluster
  255. PUBLIC RDirLen, DiskSize, SecPerFAT, BootCode, TAddr, TAddrOff, TAddrSeg
  256. PUBLIC TDone, TCount, TSector, RSEC, Read, ReadLoop, ReadDone
  257. PUBLIC ReadFinish, ReadError, WSEC, Write, WriteLoop, WriteDone, WriteFinish
  258. PUBLIC WriteError, CLIPPER, RangeError, InRange, SPEAKERCLICK, MakeClick
  259. PUBLIC NoClick, SpeakerFlag, LastTime, GS, GetSector, CantGet, LastResident
  260. PUBLIC EMMPresent, GenFailHook, EMMPresent2, MemForMe, EatingWhite, GotOption
  261. PUBLIC NoBump, NotSilence, PagesLoop, LastDigit, NotPages, NotUseAll
  262. PUBLIC Unrecognized, EndOfLine, GoodSize, GotPages, BigBust, ReTry
  263. PUBLIC GoodCombo, NoKludge, WipeOut, WipeOut2, FindFree, CalcEMMFree
  264. PUBLIC CalcDiskFree, ClickOkay, MsgOkay, InitFail, GenFail, HowMuch
  265. PUBLIC RqdPages, MajorVersion, OurVolume, Banner, EMMIDString, General
  266. PUBLIC NoEMMThere, EMMError, Init, NoMem, TooBig, BadOption, NoClicking
  267. PUBLIC Installed, DriveName, InstalledB, Installed2, UsedSpace, Bin2Dec
  268. PUBLIC Bin2DecLoop, Bin2DecDigit, WorkAreaL, WorkAreaH
  269.  
  270. ; --------------------